"""
作者: 冯勇
模块的说明: 把ecshop的首页巡检封装成一个类
"""
# 引入模块
from MY_ECShop.common.base import Base, create_browser, create_loading_browser
import time

# 将首页巡检设计成类
class PageHomepagePatrol(Base):
    # 定义属性
    url = "http://localhost:8080/ecshop/index.php"
    clothing = ('partial link text', '服装')   # 服装定位器
    simple_backpack = ('partial link text', '极简都市双肩包')  # 极简都市双肩包定位器
    portable_source = ('partial link text', '移动电源')  # 移动电源定位器
    xiaomi_mobile_power = ('partial link text', '移动电源100...')   # 小米移动电源定位器
    search = ('name', 'keywords')  # 搜索框
    search_button = ('css selector', 'input[value="搜索"]')  # 搜索按钮
    mouse_pad = ('partial link text', '鼠标垫')    # 鼠标垫定位器
    phone_type = ('partial link text', '手机类型')  # 手机类型定位器
    nokia_e66 = ('partial link text', '诺基亚E66')  # 诺基亚E66定位器
    balance_car = ('css selector', 'img[alt="平衡车"]')   # 平衡车定位器
    smart_camera = ('css selector', 'img[alt="智能相机"]')  # 智能相机定位器
    portable_fan = ('css selector', 'img[alt="随身风扇"]')  # 随身风扇定位器
    is_success = ('class name', 'goods_style_name')  # 获取文本内容
    cart = ('xpath', '//div[@id="ECS_CARTINFO"]/a')    # 获取右上角购物车文本

    # 定义方法
    """进入ECShop首页"""
    def page_homepage_open_web(self):
        self.base_open_web(self.url)    # 调用Base父类中的方法
    """点击'服装'按钮"""
    def page_homepage_clothing(self):
        self.base_click(self.clothing)
    """点击'极简都市双肩包'"""
    def page_homepage_simple_backpack(self):
        self.base_click(self.simple_backpack)
    """点击'移动电源'按钮"""
    def page_homepage_portable_source(self):
        self.base_click(self.portable_source)
    """点击'移动电源10000mAh'"""
    def page_homepage_xiaomi_mobile_power(self):
        self.base_click(self.xiaomi_mobile_power)
    """点击'手机类型'按钮"""
    def page_homepage_phone_type(self):
        self.base_click(self.phone_type)
    """点击'诺基亚E66'"""
    def page_homepage_nokia_e66(self):
        self.base_click(self.nokia_e66)
    """搜索框输入内容"""
    def page_homepage_search(self, your_message):
        self.base_input_massage(self.search, your_message)
    """点击'搜索'按钮"""
    def page_homepage_search_button(self):
        self.base_click(self.search_button)
    """点击'鼠标垫'商品"""
    def page_homepage_mouse_pad(self):
        self.base_click(self.mouse_pad)
    """获取文本内容"""
    def page_homepage_get_text(self):
        return self.base_get_text(self.is_success)

    """滚动条下拉至诺基亚e66"""
    def page_homepage_scroll_tail_nokia_e66(self):
        self.base_scroll_tail(240)

    """滚动条下拉至'1F家用电器'商品"""
    def page_homepage_scroll_tail_1F(self):
        self.base_scroll_tail(900)
    """点击'平衡车'"""
    def page_homepage_balance_car(self):
        self.base_click(self.balance_car)
    """点击'智能相机'"""
    def page_homepage_smart_camera(self):
        self.base_click(self.smart_camera)
    """点击'随身风扇'"""
    def page_homepage_portable_fan(self):
        self.base_click(self.portable_fan)

    """获取购物车标签文本"""
    def page_homepage_cart(self):
        result = self.base_get_text(self.cart)
        return result

    """关闭网页"""
    def page_homepage_quit_web(self):
        self.base_quit_web()

if __name__ == '__main__':
    # my_browser = create_browser()
    # b1 = PageHomepagePatrol(my_browser)
    b1 = PageHomepagePatrol(create_loading_browser())
    b1.page_homepage_open_web()
    time.sleep(3)
    b1.page_homepage_clothing()
    time.sleep(3)
    b1.page_homepage_simple_backpack()
    print(b1.page_homepage_get_text())
    print(b1.page_homepage_get_text())
    time.sleep(3)
    b1.page_homepage_quit_web()



